﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Management.Automation;
using PowerOBIProvider;
using System.Collections.ObjectModel;
using PowerOBIProvider.OBI;
using PowerOBIPRovider.OBIWebReference;
namespace PowerOBIProvider.Cmdlts
{
    [Cmdlet(VerbsCommon.Remove,"Account",
    SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
    public class RemoveAccountCmdlt :BaseOBICmdlt
    {

        private string accountName = null;
        [Parameter(Mandatory = true, Position = 1)]
        [ValidateNotNullOrEmpty]
        public string AccountName
        {
            get
            {
                return accountName;
            }
            set
            {
                accountName = value;
            }
        }
        
        
        private string drive = null;
        [Parameter(Mandatory = false, Position = 2)]
        [ValidateNotNullOrEmpty]
        public string Drive
        {
            get
            {
                return drive;
            }
            set
            {
                drive = value;
            }
        }
        

        protected override void ProcessRecord()
        {
            PSOBIDriveInfo obiDrive = null;
            if (drive == null)
            {
                obiDrive = GetOBIDrive(SessionState.Path.CurrentLocation);
            }
            else
            {
                obiDrive = SessionState.Drive.Get(drive) as PSOBIDriveInfo;
            }
            if ( this.ShouldProcess(accountName,
                "remove a WebCatalog account" ) )
            {
                try
                {
                    obiDrive.ObiWSClient.RemoveAccount(accountName);
                }
                catch ( Exception ex )
                {
                    WriteError(new ErrorRecord(ex, "0", ErrorCategory.OperationStopped, null));
                }
            }
        }
    }
}
